<?php

declare(strict_types=1);

namespace App\Controller\Api;

use App\Controller\AbstractController;
use Hyperf\HttpServer\Annotation\AutoController;
use Hyperf\Di\Annotation\Inject;
use Psr\EventDispatcher\EventDispatcherInterface;
use App\Event\UserRegistered;
/**
 * @AutoController()
 */
class IndexController extends AbstractController {

    /**
     * @Inject
     * @var EventDispatcherInterface
     */
    public $eventDispatcher;
    public function test() {
        $user = [
            'name'=>'张三',
            'id'=>1
        ];
        // 完成账号注册的逻辑
        // 这里 dispatch(object $event) 会逐个运行监听该事件的监听器
        $this->eventDispatcher->dispatch(new UserRegistered($user));
    }



}